package cn.dcp.muck.controller;

import cn.dcp.muck.common.entity.Paging;
import cn.dcp.muck.entity.SysDept;
import cn.dcp.muck.service.SysDeptService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;



/**
 * 部门
 * 
 * @author dcp
 * @email 631079326@qq.com
 * @date 2017-07-10 16:38:08
 */
@Api(description = "部门接口")
@Validated
@RestController
@RequestMapping("/sysdept")
public class SysDeptController extends BaseController {
	@Autowired
	private SysDeptService sysDeptService;
	
	/**
	 * 列表
	 */
    @ApiOperation(value = "部门分页列表")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "请求已完成"),
            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
            @ApiResponse(code = 500, message = "服务器不能完成请求")}
    )
    @ApiImplicitParams({
            // Filter Param
            @ApiImplicitParam(name = "query", value = "查询条件", paramType = "query", dataType = "Map"),
            // Paging Param
            @ApiImplicitParam(name = "pageNumber", value = "当前页（从0开始）", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true)
    })
	@GetMapping("/list")
	@PreAuthorize("hasAuthority('sys:dept:list')")
	public PageInfo<SysDept> list(@RequestParam Map<String, Object> query, Paging page){
        return sysDeptService.queryPage(page, query);
	}
	
	
	/**
	 * 信息
	 */
    @ApiOperation(value = "部门信息详情")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "请求已完成"),
            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
            @ApiResponse(code = 500, message = "服务器不能完成请求")}
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "String id", value = "主键", paramType = "query", dataType = "String"),
    })
	@GetMapping("/info/{id}")
	@PreAuthorize("hasAuthority('sys:dept:info')")
	public SysDept info(@PathVariable("id") String id){
        return sysDeptService.queryObject(id);
	}
	
	/**
	 * 保存
	 */
    @ApiOperation(value = "添加修改部门信息")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "请求已完成"),
            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
            @ApiResponse(code = 500, message = "服务器不能完成请求")}
    )
	@PostMapping("/save")
	@PreAuthorize("hasAuthority('sys:dept:save')")
	public SysDept save(@RequestBody SysDept sysDept){
        return	sysDeptService.save(sysDept);
	}
	
	/**
	 * 删除
	 */
    @ApiOperation(value = "删除某条部门信息")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "请求已完成"),
            @ApiResponse(code = 400, message = "请求中有语法问题，或不能满足请求"),
            @ApiResponse(code = 401, message = "未授权客户机访问数据"),
            @ApiResponse(code = 404, message = "服务器找不到给定的资源；文档不存在"),
            @ApiResponse(code = 500, message = "服务器不能完成请求")}
    )
	@DeleteMapping("/delete/{id}")
	@PreAuthorize("hasAuthority('sys:dept:delete')")
	public ResponseEntity delete(@PathVariable("id") String id){
		sysDeptService.deleteById(id);
        return new ResponseEntity(HttpStatus.OK);
	}
	
}
